const { budgetCourseModel } = require("../models");
const translateDataToTree = require("../utils/arrayToTree");
exports.create = async (req, res, next) => {
  try {
    const addOne = new budgetCourseModel(req.body);
    const ret = await addOne.save();
    res.status(200).json({
      data: ret,
    });
  } catch (err) {
    next(err);
  }
};
exports.get = async (req, res, next) => {
    try {
      const allList = await budgetCourseModel.find();
      // 根据pid 组织树结构
      const result = translateDataToTree(
        JSON.parse(JSON.stringify(allList))
      );
      res.status(200).json(result);
    } catch (err) {
      next(err);
    }
  };
  exports.delete = async (req, res, next) => {
    try {
      const ret = await budgetCourseModel.deleteMany({ _id: { $in: req.body } });
      res.status(200).json({
        data: ret,
      });
    } catch (err) {
      next(err);
    }
  };